package com.leoman.controller.backend;

import com.leoman.core.Constant;
import com.leoman.entity.Admin;
import com.leoman.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

/**
 * 总管理后台控制面板
 * Created by 涂奕恒 on 2016/11/23.
 */
@Controller
@RequestMapping(value = "backend")
public class BackendIndexController {

    @Autowired
    private UserService userService;

    @RequestMapping(value = "/dashboard")
    public String dashboard(HttpServletRequest request, ModelMap model) {
        // 获取当前登录人信息
        Admin admin = (Admin) request.getSession().getAttribute(Constant.CURRENT_ADMIN_USER);

        if (null == admin) {
            return "redirect:/login";
        }

        model.addAttribute("adminUser", admin);

        // 今日新增用户数
        model.addAttribute("todayUserCount", userService.findCountWithNewUser(0));
        // 本周新增用户数
        model.addAttribute("weekUserCount", userService.findCountWithNewUser(7));
        // 本月新增用户数
        model.addAttribute("monthUserCount", userService.findCountWithNewUser(30));
        // 总用户数
        model.addAttribute("allUserCount", userService.findCountWithNewUser(100));

        return "backend/控制面板";
    }
}
